package com.example.jh352160.surfingtv.Index.customView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.example.jh352160.surfingtv.Index.MainActivity;
import com.example.jh352160.surfingtv.Index.customView.adapter.StarsightListAdapter;
import com.example.jh352160.surfingtv.R;
import com.example.jh352160.surfingtv.network.item.IndexItem;
import com.example.jh352160.surfingtv.thematic_details.ThematicDetailsPage;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jh352160 on 2016/7/20
 */

public class Starsight extends LinearLayout {
    private Context mContext;
    ListView listView;

    public Starsight(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        init();
    }

    public Starsight(Context context) {
        super(context);
        mContext = context;
        init();
    }


    private void init() {
        LayoutInflater.from(mContext).inflate(R.layout.index_starsight, this);
        listView = (ListView) findViewById(R.id.starsight_list);
        List<ImageView> imageViews = new ArrayList<>();
        //int[] imagesId = {R.drawable.starsight_big_image, R.drawable.starsight_anne_hathaway};

        //api
        List<IndexItem.DataBean.StarBean> starBean = MainActivity.getData().getStar();
        for (IndexItem.DataBean.StarBean i : starBean) {
            final int j = i.getContentId();
            String url = i.getImageUrl();
            ImageView imageView = new ImageView(mContext);
            imageView.setMaxHeight(200);
            Glide.with(mContext).load(url).placeholder(R.drawable.starsight_anne_hathaway).into(imageView);
            imageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, ThematicDetailsPage.class);
                    intent.putExtra("contentId", j);
                    mContext.startActivity(intent);
                }
            });
            imageViews.add(imageView);
        }

        StarsightListAdapter adapter = new StarsightListAdapter(mContext, android.R.layout.simple_expandable_list_item_1, imageViews);
        listView.setAdapter(adapter);
    }
}
